using System;
using System.Collections.Generic;
using UnityEngine;

[Serializable]
public class grass_output_class
{
	public bool active;

	public bool foldout;

	public Color color_grass;

	public float strength;

	public string grass_text;

	public List<float> mix;

	public mix_mode_enum mix_mode;

	public animation_curve_math_class animation_curve_math;

	public List<animation_curve_class> curves;

	public List<grass_class> grass;

	public value_class grass_value;

	public List<float> grass_calc;

	public grass_output_class()
	{
		active = true;
		foldout = true;
		color_grass = new Color(2f, 2f, 2f, 1f);
		strength = 1f;
		grass_text = "Grass:";
		mix = new List<float>();
		animation_curve_math = new animation_curve_math_class();
		curves = new List<animation_curve_class>();
		grass = new List<grass_class>();
		grass_value = new value_class();
		grass_calc = new List<float>();
		add_grass(0);
	}

	public void add_grass(int grass_number)
	{
		grass.Insert(grass_number, new grass_class());
		grass_calc.Insert(grass_number, 0f);
		curves.Insert(grass_number, new animation_curve_class());
		mix.Insert(grass_number, 0.5f);
		grass_value.add_value(grass_number, 50f);
		set_grass_curve();
		set_grass_text();
	}

	public void erase_grass(int grass_number)
	{
		if (grass.Count > 0)
		{
			grass.RemoveAt(grass_number);
			grass_calc.RemoveAt(grass_number);
			grass_value.erase_value(grass_number);
			mix.RemoveAt(grass_number);
			curves.RemoveAt(grass_number);
			set_grass_curve();
			set_grass_text();
		}
	}

	public void clear_grass()
	{
		grass.Clear();
		grass_calc.Clear();
		grass_value.clear_value();
		mix.Clear();
		curves.Clear();
		set_grass_curve();
		set_grass_text();
	}

	public bool swap_grass(int grass_number, int grass_number2)
	{
		int result;
		if (grass_number2 > -1 && grass_number2 < grass.Count)
		{
			grass_class value = grass[grass_number];
			float value2 = grass_value.value[grass_number];
			bool value3 = grass_value.active[grass_number];
			grass[grass_number] = grass[grass_number2];
			grass[grass_number2] = value;
			grass_value.value[grass_number] = grass_value.value[grass_number2];
			grass_value.value[grass_number2] = value2;
			grass_value.active[grass_number] = grass_value.active[grass_number2];
			grass_value.active[grass_number2] = value3;
			set_grass_curve();
			result = 1;
		}
		else
		{
			result = 0;
		}
		return (byte)result != 0;
	}

	public void set_grass_curve()
	{
		float num = curves.Count;
		int num2 = 0;
		int num3 = default(int);
		Keyframe[] array = null;
		for (int i = 0; i < curves.Count; i++)
		{
			if (!grass_value.active[i])
			{
				curves[i].curve = AnimationCurve.Linear(0f, 0f, 0f, 0f);
				num -= 1f;
			}
		}
		if (num == 1f)
		{
			curves[0].curve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
			return;
		}
		float num4 = default(float);
		num4 = 1f / num;
		float num5 = default(float);
		float num6 = default(float);
		for (int i = 0; i < curves.Count; i++)
		{
			if (!grass_value.active[i])
			{
				num2++;
				continue;
			}
			num3 = i - num2;
			curves[i].curve = new AnimationCurve();
			if (mix_mode == mix_mode_enum.Single)
			{
				if (num3 == 0)
				{
					num5 = (1f - mix[1]) * (num4 / 2f);
				}
				if (num3 > 0 && !((float)num3 >= num - 1f))
				{
					num5 = (1f - mix[i]) * (num4 / 2f);
					num6 = (1f - mix[i + 1]) * (num4 / 2f);
				}
				if ((float)num3 == num - 1f)
				{
					num6 = (1f - mix[i]) * (num4 / 2f);
				}
			}
			else
			{
				num5 = (1f - mix[0]) * (num4 / 2f);
				num6 = (1f - mix[0]) * (num4 / 2f);
			}
			if (num <= 1f)
			{
				continue;
			}
			if (num3 == 0)
			{
				array = new Keyframe[3]
				{
					new Keyframe(0f, 1f),
					new Keyframe(num5 + num4 / 2f, 1f),
					new Keyframe(num4 * (float)(num3 + 1) - num5 + 1E-07f + num4 / 2f, 0f)
				};
			}
			if (num3 > 0 && !((float)num3 >= num - 1f))
			{
				array = new Keyframe[4]
				{
					new Keyframe(num4 * (float)(num3 - 1) + num5 - 1E-07f + num4 / 2f, 0f),
					new Keyframe(num4 * (float)num3 - num5 + num4 / 2f, 1f),
					default(Keyframe),
					default(Keyframe)
				};
				if (!Mathf.Approximately(num4 * (float)num3 - num5 + num4 / 2f, num4 * (float)num3 + num6 + num4 / 2f))
				{
					array[2] = new Keyframe(num4 * (float)num3 + num6 + num4 / 2f, 1f);
				}
				array[3] = new Keyframe(num4 * (float)(num3 + 1) - num6 + 1E-07f + num4 / 2f, 0f);
			}
			if ((float)num3 == num - 1f)
			{
				array = new Keyframe[3]
				{
					new Keyframe(num4 * (float)(num3 - 1) + num6 - 1E-07f + num4 / 2f, 0f),
					new Keyframe(1f - num6 - num4 / 2f, 1f),
					new Keyframe(1f, 1f)
				};
			}
			curves[i].curve = animation_curve_math.set_curve_linear(new AnimationCurve(array));
		}
	}

	public void set_grass_text()
	{
		if (grass.Count > 1)
		{
			grass_text = "Grass(" + grass.Count + ")";
		}
		else
		{
			grass_text = "Grass";
		}
	}
}
